import cv2
import numpy as np


def video_demo () :
    capture = cv2.VideoCapture ( 0 )  # 0为电脑内置摄像头
    '''
    while (True) :
        ret , frame = capture.read ( )  # 摄像头读取,ret为是否成功打开摄像头,true,false。 frame为视频的每一帧图像
        frame = cv2.flip ( frame , 1 )  # 摄像头是和人对立的，将图像左右调换回来正常显示。
        cv2.imshow ( "video" , frame )
        c = cv2.waitKey ( 50 )
        if c == 27 :
            break
    filename =  'ffff.png'
    cv2.imwrite ( 'C:/Users/*****istrator/Desktop/m' + '\\' + filename , frame )
    '''

    while (True):
        ret , frame = capture.read ()
        frame = cv2.flip ( frame , 1 )
        cv2.imshow ( "video" , frame )
        c = cv2.waitKey ( 50 )
        if c == 27 :
            break
        elif c == ord ( 'F' ) or c == ord ( 'f' ) :  # 当按下 F 键时进行截图
            filename = 'video_snapshot.png'
            cv2.imwrite ( 'D:' + '\\' + filename , frame )


video_demo ( )
cv2.destroyAllWindows ( )